package com.zu.commu.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateTime
{
  public static String getYear()
  {
    return new SimpleDateFormat("yyyy").format(
      new Date(System.currentTimeMillis()));
  }

  public static String getShortYear() {
    return new SimpleDateFormat("yy").format(
      new Date(System.currentTimeMillis()));
  }

  public static String getMonth() {
    return new SimpleDateFormat("MM").format(
      new Date(System.currentTimeMillis()));
  }

  public static String getDate() {
    return new SimpleDateFormat("dd").format(
      new Date(System.currentTimeMillis()));
  }

  public static String getHour() {
    return new SimpleDateFormat("HH").format(
      new Date(System.currentTimeMillis()));
  }

  public static String getMinute() {
    return new SimpleDateFormat("mm").format(
      new Date(System.currentTimeMillis()));
  }

  public static String getSecond() {
    return new SimpleDateFormat("ss").format(
      new Date(System.currentTimeMillis()));
  }

  public static void main(String[] args) {
    System.out.print(getWeek());
  }
  public static String getWeek() {
    String s = new SimpleDateFormat("EE").format(Long.valueOf(System.currentTimeMillis()));
    String w = "0";
    if (s.equals("星期一"))
      w = "1";
    else if (s.equals("星期二"))
      w = "2";
    else if (s.equals("星期三"))
      w = "3";
    else if (s.equals("星期四"))
      w = "4";
    else if (s.equals("星期五"))
      w = "5";
    else if (s.equals("星期六"))
      w = "6";
    else if (s.equals("星期日"))
      w = "7";
    else {
      w = s;
    }
    return w;
  }

  public static String dataTime() {
    return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(
      new Date(System.currentTimeMillis()));
  }

  public static String yyyymmdd() {
    return new SimpleDateFormat("yyyy-MM-dd").format(
      new Date(System.currentTimeMillis()));
  }

  public static String yymmddhhmmss() {
    return new SimpleDateFormat("yyMMddHHmmss").format(
      new Date(System.currentTimeMillis()));
  }

  public static String yyyymmdd(Date date) {
    return new SimpleDateFormat("yyyy-MM-dd").format(date);
  }

  public static String yyyymmddhh(Date date) {
    return new SimpleDateFormat("yyyy-MM-dd HH").format(date);
  }

  public static Date yyyymmddhh(String date) {
    try {
      return new SimpleDateFormat("yyyy-MM-dd HH").parse(date);
    } catch (Exception e) {
      try {
        return new SimpleDateFormat("yyyy-MM-dd HH")
          .parse("2000-01-01 00"); } catch (Exception localException1) {
      }
    }
    return null;
  }

  public static int compareDateStrByDate(String d1, String d2)
  {
    try {
      Date da1 = new SimpleDateFormat("yyyy-MM-dd HH").parse(d1);
      Date da2 = new SimpleDateFormat("yyyy-MM-dd HH").parse(d2);
      return da1.compareTo(da2); } catch (Exception e) {
    }
    return 0;
  }

  public static int compareDateStrByChar(String d1, String d2)
  {
    int r = 0;
    if ((d1 == null) || (d2 == null) || (d1.length() != d2.length())) {
      return r;
    }
    for (int i = 0; i < d1.length(); i++) {
      if (d1.charAt(i) > d2.charAt(i)) {
        return 1;
      }
      if (d1.charAt(i) < d2.charAt(i)) {
        return -1;
      }
    }

    return r;
  }

  public static String[] yearGroup1()
  {
    String[] years = (String[])null;
    int thisYear = Integer.parseInt(new SimpleDateFormat("yyyy")
      .format(new Date(System.currentTimeMillis())));
    int len = thisYear - 2005 + 1;
    years = new String[len];
    for (int i = 0; i < len; i++) {
      years[i] = (thisYear - i)+"";
    }
    return years;
  }

  public static String[] yearGroup2() {
    String[] years = { "1900", "1901", "1902", "1903", "1904", "1905", 
      "1906", "1907", "1908", "1909", "1910", "1911", "1912", "1913", 
      "1914", "1915", "1916", "1917", "1918", "1919", "1920", "1921", 
      "1922", "1923", "1924", "1925", "1926", "1927", "1928", "1929", 
      "1930", "1931", "1932", "1933", "1934", "1935", "1936", "1937", 
      "1938", "1939", "1940", "1941", "1942", "1943", "1944", "1945", 
      "1946", "1947", "1948", "1949", "1950", "1951", "1952", "1953", 
      "1954", "1955", "1956", "1957", "1958", "1959", "1960", "1961", 
      "1962", "1963", "1964", "1965", "1966", "1967", "1968", "1969", 
      "1970", "1971", "1972", "1973", "1974", "1975", "1976", "1977", 
      "1978", "1979", "1980", "1981", "1982", "1983", "1984", "1985", 
      "1986", "1987", "1988", "1989", "1990", "1991", "1992", "1993", 
      "1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001", 
      "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", 
      "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", 
      "2018", "2019", "2020", "2021", "2022", "2023", "2024", "2025", 
      "2026", "2027", "2028", "2029" };
    return years;
  }

  public static String[] monthGroup() {
    String[] month = { "01", "02", "03", "04", "05", "06", "07", "08", 
      "09", "10", "11", "12" };
    return month;
  }

  public static String[] dateGroup() {
    String[] date = { "01", "02", "03", "04", "05", "06", "07", "08", "09", 
      "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", 
      "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", 
      "30", "31" };
    return date;
  }

  public static String[] timeGroup() {
    String[] time = { "00", "01", "02", "03", "04", "05", "06", "07", "08", 
      "09", "11", "12", "13", "14", "15", "16", "17", "18", "19", 
      "20", "21", "22", "23" };
    return time;
  }
}